package com.yc;

import com.yc.DbConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.web.bind.annotation.*;

import javax.sql.DataSource;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/db")
public class DbSwitchController {

    @Autowired
    private DataSource dataSource;

    @Autowired
    private DbConfig dbConfig;

    @GetMapping("/student")
    public List<Map<String, Object>> queryStudent() {
        JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
        return jdbcTemplate.queryForList("SELECT * FROM student");
    }

    @GetMapping("/config")
    public DbConfig getCurrentConfig() {
        return dbConfig;
    }
}
